package com.member.provider.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.member.dto.AccessManage;
import com.member.provider.service.MemberCommercialService;
import com.member.utils.Result;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @auther liujian
 * @date 2024/1/4 14:47
 */
@RestController
@RequestMapping("/provider/commercial")
@CrossOrigin
public class MemberCommercialController {

    @Autowired
    private MemberCommercialService memberCommercialService;

    /**
     * @Description TODO
     * @param
     * @retuen Result
     * 查询商户列表
     * @date 2024/1/4 15:01
     * @auther 银狐先生
     */
//    @GetMapping("/selectAccessList")
//    public Result selectAccessList(){
//        return memberCommercialService.selectAccessList();
//    }

    /**
     * @Description TODO
     * @param payment
     * @retuen
     * @date 2024/3/6 9:37
     * @auther 银狐先生
     * 根据不同支付方式单独维护商户列表
     */
    @GetMapping("/selectAccessListByPayment")
    public Result selectAccessListByPayment(int payment){
        return memberCommercialService.selectAccessListByPayment(payment);
    }




    /**
     * @Description TODO
     * @param page,size,channelIdKq,netInTime
     * @retuen Result
     * @date 2024/3/11 13:55
     * @auther 银狐先生
     */

    @PostMapping("/selectAccessList/{page}/{size}")
    public Result selectAccessList(@PathVariable Integer page,@PathVariable Integer size,@RequestBody AccessManage accessManage, @RequestHeader("token") String token
    ){
        //解析token
        Claims claims = Jwts.parser()
                .setSigningKey("xft-ymt")
                .parseClaimsJws(token)
                .getBody();
        LambdaQueryWrapper<AccessManage> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotBlank(accessManage.getChannelIdKq())) {
            queryWrapper.eq(AccessManage::getChannelIdKq, accessManage.getChannelIdKq());
        }
        if (accessManage.getNetInTime()!=null) {
            queryWrapper.gt(AccessManage::getNetInTime, accessManage.getNetInTime());
        }
        Page<AccessManage> page1 = memberCommercialService.page(new Page<>(page, size), queryWrapper);
        return Result.success(page1);
    }
}
